<?php
/**
 * Created by PhpStorm.
 * User: alei
 * Date: 11/11/2017 AD
 * Time: 12:31
 */
namespace App\Http\Controllers\MobileApi;

trait GlobalData
{
	/**
	 * 获取配置数据：forum name => fid
	 *
	 * @return array
	 */
	public function getForumNameMapFID()
	{
		//如果缓存有从缓存取
		//TODO

		$forumNameConf = config('applqyw.lqyw_forum_name');
		$forumNameConfFlip = array_flip($forumNameConf);
		$result = \App\Models\Mysql\pre_forum_forum::getFIDbyName(array_values($forumNameConf));

		$data = [];
		foreach($result as &$v) {
			$data[$forumNameConfFlip[$v->name]] = $v->fid;
		}

		unset($forumNameConf, $forumNameConfFlip, $result);

		//结果放入缓存
		//TODO

		return $data;
	}

	/**
	 * 获取空图片的url
	 *
	 * @param $f
	 * @return string
	 */
	public static function getEmptyPicUrl($f)
	{
		switch($f) {
			case 'translationTimeEmptyPicUrl' :
				//TODO
			case 'votingTimeEmptyPicUrl' :
				//TODO

				//双语阅读主题列表接口,如果当前版块没有主题，即返回的主题列表threadList为空，
				//在主题列表区域会显示一张图片，本字段是这张图片的URL
			case 'threadListEmptyPicUrl':

		}
		return '';
	}

//	public static function get_avatar($uid, $size = 'middle', $type = '') {
//		$size = in_array($size, array('big', 'middle', 'small')) ? $size : 'middle';
//		$uid = abs(intval($uid));
//		$uid = sprintf("%09d", $uid);
//		$dir1 = substr($uid, 0, 3);
//		$dir2 = substr($uid, 3, 2);
//		$dir3 = substr($uid, 5, 2);
//		$typeadd = $type == 'real' ? '_real' : '';
//
//		return $dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2).$typeadd."_avatar_$size.jpg";
//	}

	/**
	 * 获取用户头像请求地址(目前是从pc网站服务器请求)
	 *
	 * @param int $uid
	 * @param string $size
	 * @param string $type
	 * @param string $random
	 * @param bool|FALSE $check_file_exists
	 */
	public static function get_uc_server_image_url($uid=0, $size='', $type='', $random='',
												   $check_file_exists=FALSE)
	{
		$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
		$image_server_host = config('applqyw.image_server_host');
		$image_server_dir = config('applqyw.image_server_dir');

		return $protocol.'://'.$image_server_host.'/'.$image_server_dir.'?uid='.$uid.'&size='.$size.'&type='.$type.'&random='.$random.'&check_file_exists='.$check_file_exists;
	}

	/**
	 * 首页按钮href
	 *
	 * @param $f
	 * @param $request
	 * @return string
	 */
	public static function getMenuHref($f, &$request)
	{
		if(! $f) return '';
		switch($f) {
			case 'home' :
				return '/api/home?uid='.$request->uid; //TODO
			case 'task' :
				return '/api/task?uid='.$request->uid; //TODO
			case 'translated_text' :
				return '/api/translated_text?uid='.$request->uid; //TODO
			case 'my' :
				return '/api/my?uid='.$request->uid; //TODO
			case 'bili_reading' :
				return '/api/bili_reading?uid='.$request->uid; //TODO
			case 'top_list' :
				return '/api/top_list?uid='.$request->uid; //TODO
			case 'online_dic' :
				return '/api/online_dic?uid='.$request->uid; //TODO
			case 'about_me' :
				return '/api/about_me';
			default :
				return '';
		}
	}
} //end GlobalData
